package com.chen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.config.DBUserDetailsManager;
import com.chen.entity.User;
import com.chen.mapper.UserMapper;
import com.chen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private DBUserDetailsManager dbUserDetailsManager;
   @Autowired
   private UserMapper userMapper;
    @Override
    public void saveUserDetails(User user) {

        //根据官方的代码改造
        UserDetails userDetails = org.springframework.security.core.userdetails.User.withDefaultPasswordEncoder()
                .username(user.getUsername()).password(user.getPassword()).build();
        //向数据库中插入user
        dbUserDetailsManager.createUser(userDetails);
    }
}
